﻿//2013-12-10
using System;
using System.Collections;
using PSS.DAL.SetManage.BasicData;
using PSS.Entity;
using PSS.Entity.SetManage.BasicData;
using PSS.Utility;

namespace PSS.BLL.SetManage.BasicData
{
    public class StorageBLL
    {
        private readonly StorageDAL _dal = new StorageDAL();
        public string GetStorageList(Pagination qcmodel)
        {
            var total = _dal.GetTotal();
            var list = _dal.GetStorageList(qcmodel);
            return JsonHelper.Encode(total, list);
        }
        public string GetStorageListByCombobox()
        {
            return JsonHelper.Encode(_dal.GetStorageListByCombobox());
        }
        public bool ModifyStorage(string data)
        {
            var model = new StorageEntity();
            var rows = (ArrayList)JsonHelper.Decode(data);
            foreach (Hashtable row in rows)
            {
                model.StorageId = new Guid(row["StorageId"].ToString());
                model.StorageCode = row["StorageCode"].ToString();
                model.StorageName = row["StorageName"].ToString();
                model.Status = row["Status"].ToString() == "1";
                model.Remark = row["Remark"].ToString();
            }
            return _dal.ModifyStorage(model);
        }
        public bool AddStorage(string data)
        {
            var model = new StorageEntity();
            var rows = (ArrayList)JsonHelper.Decode(data);
            foreach (Hashtable row in rows)
            {
                model.StorageId = Guid.NewGuid();
                model.StorageCode = row["StorageCode"].ToString();
                model.StorageName = row["StorageName"].ToString();
                model.Status = row["Status"].ToString() == "1";
                model.Remark = row["Remark"].ToString();
            }
            return _dal.AddStorage(model);
        }
        public string GetStorageInfo(string id)
        {
            return JsonHelper.Encode(_dal.GetStorageInfo(id));
        }
        public bool RemoveStorage(string id)
        {
            return _dal.RemoveStorage(id);
        }
    }
}
